//
//  ZCControlView.m
//  03地图定位
//
//  Created by 张聪 on 16/7/22.
//  Copyright © 2016年 张聪. All rights reserved.
//

#import "ZCControlView.h"
#import "Masonry.h"

@interface ZCControlView()

@property (nonatomic, strong) NSMutableArray *expands;


@end

@implementation ZCControlView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor grayColor];
        
        //切换地图
        NSArray *segmentes = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
        
        UISegmentedControl *segmenteControl = [[UISegmentedControl alloc] initWithItems:segmentes];
        self.segmenteControl = segmenteControl;
        
        [self addSubview:self.segmenteControl];
        
        [self.segmenteControl addTarget:self action:@selector(didSegmenteClick:) forControlEvents:UIControlEventValueChanged];
        self.segmenteControl.selectedSegmentIndex = 0;
        
        //定位返回
        UIButton *blackBtn = [[UIButton alloc] init];
        self.blackBtn = blackBtn;
        blackBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [blackBtn setTitle:@"定位返回" forState:UIControlStateNormal];
        
        blackBtn.backgroundColor = [UIColor orangeColor];
        [self addSubview:blackBtn];
        
        [self.blackBtn addTarget:self action:@selector(didBlackClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        //放大
        UIButton *bigBtn = [[UIButton alloc] init];
        self.bigBtn = bigBtn;
        bigBtn.backgroundColor = [UIColor orangeColor];
        bigBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [bigBtn setTitle:@"放大" forState:UIControlStateNormal];
        
        [self addSubview:bigBtn];
        
        [self.bigBtn addTarget:self action:@selector(didBigBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        //缩小
        UIButton *smallBtn = [[UIButton alloc] init];
        self.smallBtn = smallBtn;
        smallBtn.backgroundColor = [UIColor orangeColor];
        smallBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [smallBtn setTitle:@"缩小" forState:UIControlStateNormal];
        
        [self addSubview:smallBtn];
        
        [self.smallBtn addTarget:self action:@selector(didSmallBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        //定位大头针
        UIButton *daTouBtn = [[UIButton alloc] init];
        self.daTouBtn = daTouBtn;
        daTouBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [daTouBtn setTitle:@"开启大头针" forState:UIControlStateNormal];
        daTouBtn.backgroundColor = [UIColor orangeColor];
        
        self.daTouBtn = daTouBtn;
        [self addSubview:daTouBtn];
        [self.daTouBtn addTarget:self action:@selector(didDaTouClicks) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    return self;
}

#pragma mark - 设置子控件
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.segmenteControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.leading.equalTo(self).offset(20);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.blackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segmenteControl.mas_bottom).offset(30);
        make.leading.equalTo(self).offset(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.bigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.blackBtn.mas_bottom);
        make.trailing.equalTo(self).offset(-20);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.smallBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.blackBtn.mas_bottom);
        make.trailing.equalTo(self.bigBtn.mas_leading).offset(-20);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.daTouBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        
        make.trailing.equalTo(self).offset(-20);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        
    }];
}

#pragma mark - 响应事件
- (void)didSegmenteClick:(UISegmentedControl *)sender {
    
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"didSegmenteClicks" object:self];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didSegmenteClicks" object:self userInfo:@{@"segmentKey" : @(sender.selectedSegmentIndex)}];

}

- (void)didBlackClick {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didBlackClick" object:self];
    
    
    
}

//放大
- (void)didBigBtnClick {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"didBigBtnClick" object:self];
    
}

//缩小
- (void)didSmallBtnClick {


    [[NSNotificationCenter defaultCenter] postNotificationName:@"didSmallBtnClick" object:self];
    
    
}

- (void)didDaTouClicks {
    
    

    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didDaTouClicks" object:self];
    

    
}

#pragma mark - 懒加载
- (UIButton *)bigBtn {
    
    if (_bigBtn == nil) {
        _bigBtn = [[UIButton alloc] init];
    }
    
    return _bigBtn;
    
    
}

- (UIButton *)smallBtn {
    
    if (_smallBtn == nil) {
        _smallBtn = [[UIButton alloc] init];
    }
    
    return _smallBtn;
    
    
}

- (UIButton *)blackBtn {
    if (_blackBtn == nil) {
        _blackBtn = [[UIButton alloc] init];
    }
    
    return _blackBtn;
    
}

- (UIButton *)daTouBtn {
    
    if (_daTouBtn == nil) {
        _daTouBtn = [[UIButton alloc] init];
    }
    
    return _daTouBtn;
}

- (UISegmentedControl *)segmenteControl {
    
    if (_segmenteControl == nil) {
        _segmenteControl = [[UISegmentedControl alloc] init];
        
        
    }
    
    return _segmenteControl;
}

@end
